package com.ruoyi.merchant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.merchant.domain.MerchantFinancialFlow;
import com.ruoyi.merchant.service.IMerchantFinancialFlowService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商家收支明细Controller
 * 
 * @author ruoyi
 * @date 2025-10-23
 */
@RestController
@RequestMapping("/merchant/flow")
public class MerchantFinancialFlowController extends BaseController
{
    @Autowired
    private IMerchantFinancialFlowService merchantFinancialFlowService;

    /**
     * 查询商家收支明细列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:flow:list')")
    @GetMapping("/list")
    public TableDataInfo list(MerchantFinancialFlow merchantFinancialFlow)
    {
        startPage();
        List<MerchantFinancialFlow> list = merchantFinancialFlowService.selectMerchantFinancialFlowList(merchantFinancialFlow);
        return getDataTable(list);
    }

    /**
     * 导出商家收支明细列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:flow:export')")
    @Log(title = "商家收支明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MerchantFinancialFlow merchantFinancialFlow)
    {
        List<MerchantFinancialFlow> list = merchantFinancialFlowService.selectMerchantFinancialFlowList(merchantFinancialFlow);
        ExcelUtil<MerchantFinancialFlow> util = new ExcelUtil<MerchantFinancialFlow>(MerchantFinancialFlow.class);
        util.exportExcel(response, list, "商家收支明细数据");
    }

    /**
     * 获取商家收支明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:flow:query')")
    @GetMapping(value = "/{flowId}")
    public AjaxResult getInfo(@PathVariable("flowId") String flowId)
    {
        return success(merchantFinancialFlowService.selectMerchantFinancialFlowByFlowId(flowId));
    }

    /**
     * 新增商家收支明细
     */
    @PreAuthorize("@ss.hasPermi('merchant:flow:add')")
    @Log(title = "商家收支明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerchantFinancialFlow merchantFinancialFlow)
    {
        return toAjax(merchantFinancialFlowService.insertMerchantFinancialFlow(merchantFinancialFlow));
    }

    /**
     * 修改商家收支明细
     */
    @PreAuthorize("@ss.hasPermi('merchant:flow:edit')")
    @Log(title = "商家收支明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerchantFinancialFlow merchantFinancialFlow)
    {
        return toAjax(merchantFinancialFlowService.updateMerchantFinancialFlow(merchantFinancialFlow));
    }

    /**
     * 删除商家收支明细
     */
    @PreAuthorize("@ss.hasPermi('merchant:flow:remove')")
    @Log(title = "商家收支明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{flowIds}")
    public AjaxResult remove(@PathVariable String[] flowIds)
    {
        return toAjax(merchantFinancialFlowService.deleteMerchantFinancialFlowByFlowIds(flowIds));
    }
}
